package pers.qianyu.module.image.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.module.core.comm.HttpResult;
import pers.qianyu.module.core.comm.Pagination;
import pers.qianyu.module.core.domain.image.dto.ImageCollectionDTO;
import pers.qianyu.module.core.domain.image.query.ImageCollectionQuery;
import pers.qianyu.module.core.domain.image.vo.ImageVO;
import pers.qianyu.module.image.service.ImageCollectionService;
import pers.qianyu.module.logging.annotation.ControllerLog;
import pers.qianyu.module.logging.enums.BusinessType;

/**
 * @author mizzle rain
 * @since 2021年3月16日 20点16分
 */
@Api(tags = "收藏功能相关接口")
@RequestMapping("/image-serv")
@RestController
public class CollectionController {
    @Autowired
    private ImageCollectionService imageCollectionService;

    @ApiOperation("收藏对应图片")
    @ControllerLog(businessType = BusinessType.ADD)
    @PostMapping("/collect")
    public HttpResult<?> addCollection(@RequestBody ImageCollectionDTO imageCollectionDTO) {
        imageCollectionService.insert(imageCollectionDTO);
        return HttpResult.okWithMessage("收藏成功");
    }

    @ApiOperation("取消收藏对应图片")
    @ControllerLog(businessType = BusinessType.DELETE)
    @PostMapping("/cancel_collect")
    public HttpResult<?> cancelCollection(@RequestBody ImageCollectionDTO imageCollectionDTO) {
        imageCollectionService.delete(imageCollectionDTO);
        return HttpResult.okWithMessage("取消收藏成功");
    }

    @ApiOperation("分页查询指定用户收藏的图片集合")
    @ControllerLog(businessType = BusinessType.QUERY)
    @GetMapping("/collections")
    public HttpResult<Pagination<ImageVO>> queryCollections(ImageCollectionQuery imageCollectionQuery) {
        Pagination<ImageVO> page = imageCollectionService.queryImage(imageCollectionQuery);
        return HttpResult.okWithData(page);
    }
}
